﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using ITProject.Domain.Entities;
using System.ComponentModel.DataAnnotations;

namespace ITProject.Domain
{
    public class EFDataContext : DbContext
    {
        public DbSet<User> Users { get; set; }
        public DbSet<Project> Project { get; set; }
        public DbSet<ProjectUser> ProjectUser { get; set; }
        public DbSet<ActivationHash> ActivationHash { get; set; }
        public DbSet<Profil> Profil { get; set; }
        public DbSet<Message> Message { get; set; }
        public DbSet<Invitation> Invitation { get; set; }
        public DbSet<Team> Team { get; set; }
        public DbSet<TeamUser> TeamUser { get; set; }
        public DbSet<Release> Release { get; set; }
        public DbSet<StatusChange> StatusChange { get; set; }
        public DbSet<ReleaseStatusChange> ReleaseStatusChange { get; set; }
        public DbSet<FeatureStatusChange> FeatureStatusChange { get; set; }
        public DbSet<Feature> Feature { get; set; }
        public DbSet<FeatureTeam> FeatureTeam { get; set; }
        public DbSet<FeatureUser> FeatureUser { get; set; }
        public DbSet<FunctionalRequirement> FunctionalRequirement { get; set; }
        public DbSet<Scenario> Scenario { get; set; }
        public DbSet<FeatureFunctionalRequirement> FeatureFunctionalRequirement { get; set; }
        public DbSet<SVNHistory> SVNHistory { get; set; }
        public DbSet<Task> Task { get; set; }
        public DbSet<TaskStatusChange> TaskStatusChange { get; set; }
        public DbSet<Comment> Comments { get; set; }
        public DbSet<ForumTopic> ForumTopic { get; set; }
        public DbSet<Post> Post { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<ProjectUser>().HasKey(x => x.ProjectId).HasKey(x=>x.UserId);
            modelBuilder.Entity<Invitation>().HasKey(x => x.ProjectId).HasKey(x => x.UserId);
            modelBuilder.Entity<TeamUser>().HasKey(x => x.TeamId).HasKey(x => x.UserId);
            modelBuilder.Entity<ReleaseStatusChange>().HasKey(x => x.ReleaseId).HasKey(x => x.StatusChangeId);
            modelBuilder.Entity<FeatureStatusChange>().HasKey(x => x.FeatureId).HasKey(x => x.StatusChangeId);
            modelBuilder.Entity<TaskStatusChange>().HasKey(x => x.TaskId).HasKey(x => x.StatusChangeId);
            modelBuilder.Entity<FeatureUser>().HasKey(x => x.FeatureId).HasKey(x => x.UserId);
            modelBuilder.Entity<FeatureTeam>().HasKey(x => x.FeatureId).HasKey(x => x.TeamId);
            modelBuilder.Entity<FeatureFunctionalRequirement>().HasKey(x => x.FeatureId).HasKey(x => x.RequirementId);
            modelBuilder.Entity<Scenario>().HasKey(x => x.Id).Property(x => x.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
            base.OnModelCreating(modelBuilder);
        }
    }
}
